project(utkcore LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Xml Network)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Xml Network)

set(OpenSSL_DIR "${QT_DIR}/../../../../../Tools/OpenSSL/Win_x64")
message(OpenSSL_DIR==========:${OpenSSL_DIR})

INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/crashhandler/crashhandler.cmake)
INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/serializer/serializer.cmake)
INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/mqtt/qmqtt.cmake)

FILE(GLOB HEADERS
    ${CMAKE_CURRENT_SOURCE_DIR}/*.h
    ${CMAKE_CURRENT_SOURCE_DIR}/message/*.h
    ${CMAKE_CURRENT_SOURCE_DIR}/thread/*.h
    ${CMAKE_CURRENT_SOURCE_DIR}/json/*.h
    ${CMAKE_CURRENT_SOURCE_DIR}/plugin/*.h
    ${CMAKE_CURRENT_SOURCE_DIR}/encrypt/*.h
    ${SERIALIZER_HEADERS}
    ${QMQTT_HEADERS}
)

FILE(GLOB SOURCES
    ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/message/*.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/thread/*.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/json/*.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/plugin/*.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/encrypt/*.cpp
    ${SERIALIZER_SOURCES}
    ${QMQTT_SOURCES}
)

set(PROJECT_SOURCES
    ${HEADERS}
    ${SOURCES}
    ${RESOURCES}
)

include_directories(${OpenSSL_DIR}/include)
link_directories(${OpenSSL_DIR}/lib)
set(OpenSSL_LIB "libssl" "libcrypto")

add_library(utkcore SHARED ${PROJECT_SOURCES})

target_link_libraries(utkcore PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Xml
    Qt${QT_VERSION_MAJOR}::Network Qt${QT_VERSION_MAJOR}::CorePrivate ${OpenSSL_LIB})

target_compile_definitions(utkcore PRIVATE UTKCORE_LIBRARY)

add_subdirectory(qhttpengine)
